(function() {
    var myApp = angular.module('myApp');

    myApp.controller("myUserSettingsController", function($scope, $rootScope, $log, reqDataByAjax, $location) {
        reqDataByAjax("/scheduling/api/settings/user/get").then(function (ret) {
            $scope.user = ret[0][0];
        });
        
        
        $scope.passwordChange = function() {
        	$scope.user.showFlag =false;
        	
        	 var rules=[{
                 reg:/\d+/,
                 weight:2
             },{
                 reg:/[a-z]+/,
                 weight:4
             },{
                 reg:/[A-Z]+/,
                 weight:8
             },{
                 reg:/[~!@#\$%^&*\(\)\{\};,.\?\/'"]/,
                 weight:16
             }];
             
             var strongLevel={
                 '0-10':'弱',
                 '10-20':'中',
                 '20-30':'强'
             };
             
            
             var weight=0;
             for(var j=rules.length-1;j>=0;j--){
                 if(rules[j].reg.test($scope.user.password)){
                     weight|=rules[j].weight;
                 }
             }
             var key='20-30';
             if(weight<=10) {
                 key='0-10';
             }
             else if(weight<=20) {
                 key='10-20';
             }
             
             // 密码小于8位
             if($scope.user.password.length < 8){
                 key='0-10';
             }
             
             // 显示级别
             $scope.user.level = strongLevel[key];
             
             $scope.user.showFlag =true;
        	
        }
    
        $scope.ok = function(e) {
        	
        	if($scope.user.password == "" || $scope.user.passwordRepeat == "" ){
        		alert('请输入新密码!');
        		return;
        	}else if($scope.user.password != $scope.user.passwordRepeat){
        		alert('重复密码与新密码输入不一致!');
        		return;
        	}else{
        		reqDataByAjax("/scheduling/api/settings/user/save", $scope.user, "POST")
                .then(function(data) {
                    // 显示已保存对话框;
                	alert("保存成功！");
//                	$location.path("scheduling/page/shortcut/home");
                	window.location.replace("/scheduling/page/shortcut/home");
                });
        	}
        	
            
        }
    });

})();
